<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="copyright" content="All Rights Reserved, Copyright (C) 2013, Wuyeguo, Ltd."/>
    <title>智能应急快速搭建平台V1.0</title>
    <script type="text/javascript" src="../../js/commonCss.js"></script>
    <script type="text/javascript" src="../../js/commonJs.js"></script>
</head>
<div class="easyui-layout" data-options="fit:true">
    <!-- Begin of toolbar -->
    <div id="wu-toolbar-pro">
        <div class="wu-toolbar-button">
            <a href="#" class="easyui-linkbutton" iconCls="icon-remove" onclick="remove()" plain="true">删除</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-remove" onclick="run()" plain="true">启动</a>
        </div>
        <div class="wu-toolbar-search">
            <label>流程名称：</label><input id="name" class="wu-text" style="width:100px">
            <a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="doSearch()">开始检索</a>
        </div>
    </div>
    <!-- End of toolbar -->
    <table id="wu-datagrid-pro" class="easyui-datagrid" toolbar="#wu-toolbar-pro"></table>
</div>
<!-- Begin of easyui-dialog -->
<div id="wu-dialog-pro" class="easyui-dialog" data-options="closed:true,iconCls:'icon-save'" style="width:1100px; height:550px; padding:10px;">

</div>
<!-- End of easyui-dialog -->
<script type="text/javascript">

    /**
     * Name 查询
     */
    function doSearch(){
        //$('#tt').datagrid('load',{
          //  itemid: $('#itemid').val(),
            //productid: $('#productid').val()
        //});

        var paramData = {
            createTime: $('#createTime').val(),
            lastUpdateTime: $('#lastUpdateTime').val(),  //须要查询的对象
            id: $('#id').val(),
            name: $('#name').val()
        };
        console.log(JSON.stringify(paramData))



        $('#wu-datagrid-pro').datagrid('load',{paramData:JSON.stringify(paramData)});
    }


	/**
	* Name 添加记录
	*/
	function add(){
		$('#wu-form-pro').form('submit', {
			url:'',
			success:function(data){
				if(data){
					$.messager.alert('信息提示','提交成功！','info');
					$('#wu-dialog-pro').dialog('close');
				}
				else
				{
					$.messager.alert('信息提示','提交失败！','info');
				}
			}
		});
	}

	/**
	* Name 修改记录
	*/
	function edit(){
		$('#wu-form-pro').form('submit', {
			url:'',
			success:function(data){
				if(data){
					$.messager.alert('信息提示','提交成功！','info');
					$('#wu-dialog-pro').dialog('close');
				}
				else
				{
					$.messager.alert('信息提示','提交失败！','info');
				}
			}
		});
	}

	/**
	* Name 删除记录
	*/
	function remove(){
		$.messager.confirm('信息提示','确定要删除该记录？', function(result){
			if(result){
				var items = $('#wu-datagrid-pro').datagrid('getSelections');
				var ids = [];
				$(items).each(function(){
					ids.push(this.id);
				});
				//alert(ids);return;
				$.ajax({
					url:'/activiti/deleteByIds',
					data:'ids='+ids,
					success:function(data){
						if(data){
							$.messager.alert('信息提示','删除成功！','info');
                            $('#wu-datagrid-pro').datagrid();
						}
						else
						{
							$.messager.alert('信息提示','删除失败！','info');
						}
					}
				});
			}
		});
	}


    function run(){
        $.messager.confirm('信息提示','确定发起流程？', function(result){
            if(result){
                var items = $('#wu-datagrid-pro').datagrid('getSelections');
                var ids = [];
                $(items).each(function(){
                    ids.push(this.key);
                });
                //alert(ids);return;
                $.ajax({
                    type: 'POST',
                    contentType: "application/json;charset=UTF-8",
                    dataType: 'json',
                    data:'{"proDefId":"354bfc8","bussId":"ZFW42010000020190422QB001","bussName":"宁波市市情报001","bussType":"SB","startUserId":"admin","targetUnitId":"ZFW420000000"}',
                    url:'/process/run/'+ids,
                    success:function(data){
                        if(data){
                            $.messager.alert('信息提示','发起成功！','info');
                            $('#wu-datagrid-pro').datagrid();
                        }
                        else
                        {
                            $.messager.alert('信息提示','发起失败！','info');
                        }
                    }
                });
            }
        });
    }


	/**
	* Name 打开添加窗口
	*/
	function openAdd(){
		$('#wu-form-pro').form('clear');
		$('#wu-dialog-pro').dialog({
           // href: '/activiti/create',
            content:"<iframe scrolling='auto' frameborder='0' src='/activiti/create' style='width:100%; height:100%; display:block;'></iframe>",
			closed: false,
			modal:true,
            title: "添加信息",
            buttons: [{
                text: '确定',
                iconCls: 'icon-ok',
                handler: add
            }, {
                text: '取消',
                iconCls: 'icon-cancel',
                handler: function () {
                    $('#wu-dialog-pro').dialog('close');
                }
            }]
        });
	}

	/**
	* Name 打开修改窗口
	*/
	function openEdit(){
		$('#wu-form-pro').form('clear');
		var item = $('#wu-datagrid-pro').datagrid('getSelected');
        var id = item.id;
		$('#wu-dialog-pro').dialog({
            content:"<iframe scrolling='auto' frameborder='0' src='/activiti/editor?modelId="+id+"' style='width:100%; height:100%; display:block;'></iframe>",
            closed: false,
			modal:true,
            title: "修改信息",
            buttons: [{
                text: '确定',
                iconCls: 'icon-ok',
                handler: edit
            }, {
                text: '取消',
                iconCls: 'icon-cancel',
                handler: function () {
                    $('#wu-dialog-pro').dialog('close');
                }
            }]
        });
	}

    function showImage(id){
        $('#wu-dialog-pro').dialog({
            content:"<iframe scrolling='auto' frameborder='0' src='/process/show?did="+id+"&ext=.png' style='width:100%; height:100%; display:block;'></iframe>",
            closed: false,
            modal:true,
            title: "流程"
        });

    }

    function openApple(){
        var item = $('#wu-datagrid-pro').datagrid('getSelected');
        var id = item.key;
        $('#wu-dialog-pro').dialog({
            content:"<iframe id='apple' scrolling='auto' frameborder='0' src='/easyui/act/process/apple.html?taskId="+id+"' style='width:100%; height:100%; display:block;'></iframe>",
            closed: false,
            modal:true,
            title: "提交信息",
            buttons: [{
                text: '提交',
                iconCls: 'icon-ok',
                handler: function(){
                    //获取iframe里面的内容
                    var childWin = document.getElementById('apple').contentWindow;
                    //调用子页面对象,子页面的方法
                    childWin.appletest();
                    $.messager.alert('信息提示','提交成功！','info');
                    //var rows = childWin.selectedDevListGrid.getSelectDevList();
                    $('#wu-dialog-pro').dialog('close');
                }
            }, {
                text: '取消',
                iconCls: 'icon-cancel',
                handler: function () {
                    $('#wu-dialog-pro').dialog('close');
                }
            }]
        });
    }

	/**
	* Name 载入数据
	*/
	$('#wu-datagrid-pro').datagrid({
        url:'/process/list2',
		//loadFilter:pagerFilter,
		rownumbers:true,
		pageSize:20,
		pagination:true,
		fitColumns:true,
		fit:true,
        pageList: [10, 20, 50, 100, 150, 200],
        columns:[[
			{ checkbox:true},
			{ field:'id',title:'id',width:100,sortable:true,align:'center'},
            { field:'name',title:'流程名称',width:100,sortable:true,align:'center'},
			{ field:'key',
                title:'key',
                width:180,
                sortable:true,
                align:'center',
                formatter: function (value, data) {
                    return '<a style="color: blue;" href="javascript:openApple()">申请</a>';
                }
            },
			{ field:'diagramResourceName',
                title:'流程图',
                width:100,
                align:'center',
                formatter: function (value, data) {
                    return '<a style="color: blue;" href="javascript:showImage(\''+data.deploymentId+'\')">流程图</a>';
                }
            },
            { field:'deploymentId',title:'流程id',width:100,align:'center'},
			{ field:'version',
                title:'版本号',
                width:100,
                align:'center',
                formatter: function (value, data) {
                    return '<a style="color: blue;" >V' + data.version + '.0</a>';
                }
            }
		]]
	});
</script>